<?php global $has_permit; ?>
<div class="std_header auto_height">
    <div class="left">
        <strong><?php echo $module['title']; ?></strong>
    </div>
    <div class="right">
        <button class="gray_btn" onclick="admin_site_banner.create_new()"><span>Thêm mới</span></button>
    </div>
</div>
<div class="db_left bl">
    <?php $this->load->view('layouts/side_block'); ?>
</div>
<div class="db_right bl">
    <?php if ($has_permit) :?>
    <div id="banner_management">
        <div id="tab_store" class="tab_container">
            <ul>
                <li id="active_tab_list"><a href="#tab_list"><span>Danh sách Banner</span></a></li>
                <li id="active_tab_edit"><a href="#tab_edit"><span>Thông tin Banner</span></a></li>
            </ul>
            <div id="tab_list">
                <?php if (count($collection) != 0) : ?>
                <?php $this->load->view('site/banner/message'); ?>
                <form enctype="multipart/form-data" action="<?php echo site_url('admin/site/banner/index', true); ?>" method="post" id="frm_banner_gridview">
                    <div class="block">
                        <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
                            <thead>
                            <tr>
                                <td><b>ID</b></td>
                                <td><b>Ảnh</b></td>
                                <td><b>Tên</b></td>
                                <td><b>Xử lý</b></td>
                            </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($collection as $banner) : ?>
                                <tr>
                                    <td width="30px" valign="top">
                                        <?php echo $banner->id; ?>
                                    </td>
                                    <td width="150px" valign="top">
                                        <div class="frame">
                                        <?php if (!empty($banner->file)) :?>
                                            <img src="<?php echo render_src($banner->file); ?>" width="120px" />
                                        <?php else :?>
                                            <img src="<?php echo BASE_URL; ?>themes/standard/images/no_image.gif" width="120px" />
                                        <?php endif; ?>
                                        </div>
                                    </td>
                                    <td valign="top">
                                        <p><?php if ($banner->is_visible == 1) :?><span class="icon icon_active"></span><?php endif; ?><a class="ajax_link" data="{id:<?php echo $banner->id; ?>}" selector="#tab_edit" item="#active_tab_edit a" href="<?php echo site_url('admin/site/banner/ajax_edit/id/' . $banner->id, true); ?>"><strong><?php echo $banner->name; ?></strong></a></p>
                                        <p class="mt_10"><span class="icon icon_link"></span> <a href="<?php echo $banner->link; ?>" target="_blank"><?php echo $banner->link; ?></a></p>
                                        <p class="small_datetime mt_10"><span class="icon icon_author"></span> Upload <?php if (!empty($banner->uploader)) :?>bởi: <strong><?php echo $banner->uploader; ?></strong><?php endif; ?> vào lúc <?php echo date('H:i, d/m/Y', $banner->created_at); ?></p>
                                    </td>
                                    <td valign="top">
                                        <p><a class="ajax_link icon icon_edit" data="{id:<?php echo $banner->id; ?>}" selector="#tab_edit" item="#active_tab_edit a" href="<?php echo site_url('admin/site/banner/ajax_edit/id/' . $banner->id, true); ?>"></a> <a class="icon icon_delete" href="<?php echo site_url('admin/site/banner/delete/id/' . $banner->id, true); ?>" onclick="return confirm('Bạn muốn xóa banner này?')"></a></p>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            </tbody>
                            <tfoot>

                            </tfoot>
                        </table>
                    </div>
                </form>
                <?php else : ?>
                <div class="error_message corner">Không tìm thấy banner nào</div>
                <?php endif; ?>
            </div>
            <div id="tab_edit">
                <form id="frm_banner_edit" method="POST" action="<?php echo $save_action; ?>" enctype="multipart/form-data">
                    <div class="clearfix auto_height mb_10">
                        <button class="gray_btn active_item" type="button" item="#active_tab_list a"><span>Về danh sách</span></button>
                        <button class="gray_btn" type="submit"><span>Lưu lại</span></button>
                        <button class="gray_btn" type="reset"><span>Nhập lại</span></button>
                    </div>
                    <div class="form_block">
                        <div class="block_header">
                            Thông tin căn bản
                        </div>
                        <div class="block_content">
                            <table cellpadding="0px" cellspacing="0px">
                                <?php if (isset($zones) && $zones && count($zones) > 0) :?>
                                <tr>
                                    <td class="frm_label">Vùng hiển thị(*)</td>
                                    <td class="frm_field">
                                        <select class="std_input" name="data[zone_id]" style="width: 200px">
                                            <?php foreach ($zones as $zone) :?>
                                            <option value="<?php echo $zone->id; ?>"><?php echo $zone->heading; ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </td>
                                </tr>
                                <?php endif; ?>
                                <tr>
                                    <td class="frm_label">File upload(*)</td>
                                    <td class="frm_field">
                                        <input type="file" name="data_file" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Tiêu đề(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[name]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Mã banner</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input" name="data[alias]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Thứ tự</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required digits" name="data[sort_order]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Liên kết</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[link]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Chiều dài</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[width]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Chiều rộng</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[height]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Hiển thị</td>
                                    <td class="frm_field">
                                        <select id="banner_display" class="std_input" name="data[display]" style="width: 200px;">
                                            <option value="-1">Chọn chế độ</option>
                                            <?php foreach ($this->site_banner_model->get_display_mode() as $value => $label) :?>
                                            <option value="<?php echo $value; ?>"><?php echo $label; ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Chuyển hướng</td>
                                    <td class="frm_field">
                                        <select id="banner_target" class="std_input" name="data[target]" style="width: 200px">
                                            <option value="-1">Chọn chế độ chuyển hướng</option>
                                            <?php foreach ($this->site_banner_model->get_target_mode() as $value => $label) :?>
                                            <option value="<?php echo $value; ?>"><?php echo $label; ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Ẩn hiện(*)</td>
                                    <td class="frm_field">
                                        <label>
                                            <input type="checkbox" value="1" checked="checked" name="data[is_visible]" />
                                            <span>Hiện / Ẩn</span>
                                        </label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Hiển thị từ ngày</td>
                                    <td class="frm_field">
                                        <input name="data[visible_from]" placeholder="Hiển thị từ ngày" type="text" class="std_input date_picker" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Hiển thị đến ngày</td>
                                    <td class="frm_field">
                                        <input name="data[visible_to]" placeholder="Hiển thị đến ngày" type="text" class="std_input date_picker" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="clearfix auto_height">
                        <button class="gray_btn active_item" type="button" item="#active_tab_list a"><span>Về danh sách</span></button>
                        <button class="gray_btn" type="submit"><span>Lưu lại</span></button>
                        <button class="gray_btn" type="reset"><span>Nhập lại</span></button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php else :?>
    <?php $this->load->view('layouts/restricted'); ?>
    <?php endif; ?>
</div>
<div class="clearfix"></div>
<script type="text/javascript">
    $("#frm_banner_edit").validate();
</script>
<script type="text/javascript" src="<?php echo BASE_URL; ?>js/admin/site/banner/function.js"></script>